package com.lwl.blog.core.service;

import com.lwl.blog.core.dao.IBaseDao;

import java.sql.SQLException;
import java.util.List;

/**
 * 共有业务层抽象接口
 * @param <T>
 */
public abstract class BaseServiceImpl<T> implements IBaseService<T>{
    protected abstract IBaseDao<T> getBaseDao(); // 这里只是申明了,需要实例化

    @Override
    public boolean save(T t) throws Exception {
        return getBaseDao().insert(t)>0;
    }

    @Override
    public boolean update(T t) throws Exception {
        return getBaseDao().updateById(t)>0;
    }

    @Override
    public boolean remove(Integer id) throws Exception {
        return getBaseDao().deleteById(id)>0;
    }

    @Override
    public T byId(Integer id) throws Exception {
        return getBaseDao().selectById(id);
    }

    @Override
    public List<T> list() throws Exception {
        return getBaseDao().selectList();
    }

    @Override
    public boolean batchRemove(List<Integer> ids) throws SQLException {
        return getBaseDao().batchRemove(ids)>0;
    }
}
